<template>
  <div class="digital-mall">
    <!-- Banner区域 -->
    <Banner>
      <template #title>
        <h1>数码商城</h1>
      </template>
      <template #subtitle>
        <p>官方正品·品质保障</p>
      </template>
    </Banner>

    <div class="main-layout">
      <!-- 左侧分类菜单 -->
      <aside class="sidebar">
        <h2 class="sidebar-title">商品分类</h2>
        <TabContainer
          :categories="categories"
          v-model:active-category="activeCategory"
        >
          <template #default="{ category }">
            <div
              class="category-item"
              :class="{ active: category.id === activeCategory }"
              @click="handleCategoryClick(category.id)"
            >
              <span class="category-name">{{ category.name }}</span>
            </div>
          </template>
        </TabContainer>
      </aside>

      <!-- 右侧商品内容 -->
      <main class="content">
        <div class="category-info">
          <h2 class="category-title">{{ getCurrentCategoryName() }}</h2>
          <p class="category-desc">{{ getCurrentCategoryDesc() }}</p>
        </div>

        <!-- 商品列表 -->
        <ProductList :category-id="activeCategory" />

        <div class="current-section">
          当前专区ID：{{ activeCategory }}
        </div>
      </main>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import Banner from '../components/Banner.vue'
import TabContainer from '../components/TabContainer.vue'
import ProductList from '../components/ProductList.vue'

// 分类数据
const categories = ref([
  { id: 1, name: '手机专区', description: '最新智能手机，5G机型，旗舰性能，超长续航，满足您的各种需求。' },
  { id: 2, name: '笔记本专区', description: '高性能笔记本电脑，轻薄便携，商务办公，游戏娱乐一应俱全。' },
  { id: 3, name: '配件专区', description: '手机配件、电脑配件、保护壳、充电器等各类数码配件。' }
])

const activeCategory = ref(3) // 默认显示配件专区

const handleCategoryClick = (categoryId: number) => {
  activeCategory.value = categoryId
}

const getCurrentCategoryName = () => {
  const category = categories.value.find(cat => cat.id === activeCategory.value)
  return category ? category.name : ''
}

const getCurrentCategoryDesc = () => {
  const category = categories.value.find(cat => cat.id === activeCategory.value)
  return category ? category.description : ''
}
</script>

<style scoped>
.digital-mall {
  min-height: 100vh;
  background-color: #f5f5f5;
  display: flex;
  flex-direction: column;
}

.main-layout {
  display: flex;
  flex: 1;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  gap: 0;
}

.sidebar {
  width: 250px;
  background: white;
  padding: 30px 20px;
  border-right: 1px solid #e8e8e8;
  min-height: calc(100vh - 140px);
}

.sidebar-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 25px;
  color: #333;
  padding-bottom: 10px;
  border-bottom: 2px solid #42b883;
}

.category-item {
  padding: 15px 20px;
  margin: 8px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #e8e8e8;
  font-size: 16px;
}

.category-item:hover {
  background-color: #f0f9ff;
  border-color: #42b883;
}

.category-item.active {
  background-color: #42b883;
  color: white;
  border-color: #42b883;
}

.category-name {
  font-weight: 500;
}

.content {
  flex: 1;
  padding: 40px;
  min-height: calc(100vh - 140px);
  background: white;
}

.category-info {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e8e8e8;
}

.category-title {
  font-size: 28px;
  font-weight: bold;
  color: #333;
  margin-bottom: 12px;
}

.category-desc {
  font-size: 16px;
  color: #666;
  line-height: 1.6;
}

.current-section {
  margin-top: 40px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
  font-size: 16px;
  color: #666;
  text-align: center;
  border: 1px solid #e8e8e8;
}
</style>